package com.fan.gofast.compent;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @ClassName ApplicationUtils
 * @Decription
 * @Author wangjing
 * @Date 2019/3/14 16:36
 **/
@Component
public class ApplicationUtils {

    private static ApplicationContext ac;

    public ApplicationUtils(ApplicationContext applicationContext) {
        ac = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return ac;
    }

    public static <T> T get(Class<T> clazz) {
        return getApplicationContext().getBean(clazz);
    }

    public static <T> T get(String name, Class<T> clazz) {
        return getApplicationContext().getBean(name, clazz);
    }

    public static Object get(String name) {
        return getApplicationContext().getBean(name);
    }
    public static String getStaticDomain(){
        return getApplicationContext().getEnvironment().getProperty("spring.metadata.static-domain");
    }
    public static String getProperty(String key) {
        return getApplicationContext().getEnvironment().getProperty(key);
    }
    public static String getActiveProfile() {
        return getProperty("spring.profiles.active");
    }
}
